package  
{
	import flash.events.TextEvent;
	import net.flashpunk.Entity;
	import net.flashpunk.FP;
	import net.flashpunk.graphics.Text;
	import net.flashpunk.utils.Input;
	import net.flashpunk.utils.Key;
	
	/**
	 * ...
	 * @author Edward Russell II
	 */
	public class HUD extends Entity 
	{
		//Here we create the text objects we're gonig to be using for the hud.
		protected var txt_score:Text;
		protected var txt_gameOver:Text;
		protected var txt_pressEnter:Text;
		protected var txt_highScore:Text;
		protected var txt_currentHeat:Text;
		
		
		//These are the strings we use display the score
		protected var str_Score:String = "Score: "
		protected var str_HighScore:String = "Highscore: "
		
		public function HUD() 
		{
			
			//Set the HUD to be the topmost layer
			this.layer = -4;
			
			//Setup the Score object
			txt_score = new Text(str_Score);
			txt_score.align = "right";
			txt_score.width = FP.screen.width;
			txt_score.size = 32;
			
			//Setup the High Score object
			txt_highScore = new Text(str_HighScore);
			txt_highScore.width = FP.screen.width;
			txt_highScore.size = 32;
			
			//Setup the Game Over object just above the center of the screen
			txt_gameOver = new Text("GAME OVER");
			txt_gameOver.scale = 2;
			txt_gameOver.x = FP.screen.width / 2 - txt_gameOver.scaledWidth;
			txt_gameOver.y = FP.screen.height / 3;
			txt_gameOver.size = 32
			
			//Setup the second line of the Game Over object
			txt_pressEnter = new Text("PRESS ENTER TO RETRY");
			txt_pressEnter.x = FP.screen.width / 2 - txt_pressEnter.width;
			txt_pressEnter.y = txt_gameOver.y + txt_gameOver.scaledHeight;
			txt_pressEnter.size = 32;
			
			txt_currentHeat = new Text("0")
			txt_currentHeat.y = FP.screen.height - txt_currentHeat.height;
			
			//Add everything to the scree
			addGraphic(txt_score);
			addGraphic(txt_highScore);
			addGraphic(txt_currentHeat);
		}
		override public function update():void 
		{
			//Here we check to see if it is Game Over
			if (GV.GAME_OVER)
			{
				addGraphic(txt_gameOver);
				addGraphic(txt_pressEnter);
				
				if (Input.pressed(Key.ENTER)) reset(); //Call the reset() function
			}
			
			
			//move the HUD along with our camera
			this.x = FP.camera.x;
			this.y = FP.camera.y;
			
			//update the scores on the HUD
			txt_score.text =  str_Score.concat(String(GV.SCORE));
			txt_highScore.text =  str_HighScore.concat(String(GV.HIGH_SCORE));
			txt_currentHeat.text = String(Player.gun.currentHeat);
			
			super.update();
		}
		
		public function reset():void
		{
			GV.SCORE = 0;
			GV.GAME_OVER = false;
			world.end();
			FP.world = new GameWorld();
		}
		
	}

}